package com.panda.common.http.session;

import com.panda.common.memcached.MemcachedManager;

/**
 * 
 * @author liuxiaobei
 *
 */
public class SvSessionImpl implements SvSession {
	
	private String sessionKey;
	
	private String categoryKey;
	
	public long lifeCycle = 24*3600*1000;
	
	public SvSessionImpl(String SessionKey) {
		this.sessionKey = SessionKey;
	}
	
	public void setAttribute(String key, Object obj) {
		if (key == null) {
			throw new IllegalArgumentException("key not be null!");
		}
		if(obj != null) {
			categoryKey = sessionKey + "_" + key;
			MemcachedManager.set(categoryKey, obj, lifeCycle);
		}
	}
	
	
	public void setAttribute(String key, Object obj , long lifeCycle) {
		if (key == null) {
			throw new IllegalArgumentException("key not be null!");
		}
		if(obj != null) {
			categoryKey = sessionKey + "_" + key;
			MemcachedManager.set(categoryKey, obj, lifeCycle);
		}
	}
	
	
	public Object getAttribute(String key) {
		if (key == null) {
			throw new IllegalArgumentException("key not be null!");
		}
		categoryKey = sessionKey + "_" + key;
		return MemcachedManager.get(categoryKey);
	}

	public void removeAttribute(String key) {
		if (key == null) {
			throw new IllegalArgumentException("key not be null!");
		}
		categoryKey = sessionKey + "_" + key;
		MemcachedManager.delete(categoryKey);
	}

	@Override
	public long getCreationTime() {
		// TODO Auto-generated method stub
		return 0;
	}
}
